博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
stark组件之分页【模仿Django的admin】
阅读量:6207 次
发布时间:2019-06-21

本文共 3837 字,大约阅读时间需要 12 分钟。

我们的stark组件用的我们的分页组件,没有重新写

 

 

 

下面直接看下分页的代码

class page_helper():    def __init__(self, count, current_page, per_page_num, base_url,parms):        self.count = count        self.current_page = current_page        self.per_page_num = per_page_num        self.base_url = base_url        self.page_head = "
" import copy parms = copy.deepcopy(parms) parms._mutable = True self.parms = parms def page_count(self): before, after = divmod(self.count, self.per_page_num) if after > 0: class_count = before + 1 else: class_count = before print("-------------",class_count,self.count,self.per_page_num) return class_count def page_start(self): if self.page_count() <= 11: start_int = 1 end_int = self.page_count() else: if self.current_page <= 6: start_int = 1 end_int = 11 elif self.current_page + 5 + 1 > self.page_count(): start_int = self.page_count() - 10 end_int = self.page_count() + 1 else: start_int = self.current_page - 5 end_int = self.current_page + 5 + 1 return start_int def page_end(self): if self.page_count() <= 11: start_int = 1 end_int = self.page_count() else: if self.current_page <= 6: start_int = 1 end_int = 11 elif self.current_page + 5 + 1 > self.page_count(): start_int = self.page_count() - 10 end_int = self.page_count() + 1 else: start_int = self.current_page - 5 end_int = self.current_page + 5 + 1 return end_int def db_start(self): return (self.current_page - 1) * self.per_page_num + 1 def db_end(self): return self.current_page * self.per_page_num + 1 def page_list(self): print(self.parms,dir(self.parms),"======================",self.parms.urlencode()) if self.current_page == 1: before_page = "
  • " else: self.parms["p"] = self.current_page - 1 before_page = "
  • ".format(url=self.base_url, args=self.parms.urlencode()) page_list = [] page_list.append(before_page) for i in range(self.page_start(), self.page_end() + 1): self.parms["p"] = i if i == self.current_page: s = """
  • {num}
  • """.format(url=self.base_url, args=self.parms.urlencode(),num=self.parms["p"]) else: s = """
  • {num}
  • """.format(url=self.base_url, args=self.parms.urlencode(),num=self.parms["p"]) page_list.append(s) if self.current_page == self.page_count(): after_page = """
  • """ else: self.parms["p"] = self.current_page + 1 after_page = """
  • """.format(url=self.base_url, args=self.parms.urlencode()) page_list.append(after_page) page_body = "".join(page_list) page_str = self.page_head + page_body + self.page_tail return page_str

      

     

    分页的代码在什么实用用呢?应该list_url这个函数把过滤和搜索后的数据传递个showlist这个类,然后这个类在根据这些要显示的数据在进行分页

    class Showlist(object):    def __init__(self,config,request,new_list,new_data_list):        self.config = config        self.request = request        self.new_list = new_list        self.new_data_list = new_data_list        # 分页显示        count = self.new_data_list.count()        current_page = int(request.GET.get("p",1))        per_page_num = 3        base_url = request.path_info        parms = request.GET        self.page_str = page.page_helper(count=count,current_page=current_page,per_page_num=per_page_num,base_url=base_url,parms=parms)

      

     

     

    转载于:https://www.cnblogs.com/bainianminguo/p/10134955.html

    你可能感兴趣的文章
    【java】实体类中 Set<对象> 按照对象的某个字段对set排序
    查看>>
    Android Butterknife 8.4.0 使用方法总结
    查看>>
    横向滑动的HorizontalListView滑动指定位置的解决方法
    查看>>
    2013百度校招笔试真题以及解析(内存管理及其优缺点总结)
    查看>>
    自制DbHelper实现自动化数据库交互
    查看>>
    195.3. fonts 字体
    查看>>
    2014年度总结2015展望
    查看>>
    微信小程序之页面路由
    查看>>
    SAP Batch Management - Price Determination for Batches
    查看>>
    队列、资源与锁
    查看>>
    云计算大会第三批议题:金融、医疗等六大行业
    查看>>
    自动精简配置&重复数据删除核心技术点及其经济效应探究
    查看>>
    退伍军人建伪基站闯大祸:60万用户断网
    查看>>
    云计算促进健全现有IT管理体制
    查看>>
    大连银行应用Informatica数据脱敏方案
    查看>>
    F5发布最新文件虚拟化存储产品ARX 4000
    查看>>
    电信大数据变现带来的跨界效应
    查看>>
    cncert网络安全周报35期 境内被植入后门的政府网站112个 环比上涨24.4%
    查看>>
    校际合作+无线教育 打造“互联学校”新模式
    查看>>
    CommVault在北京推出下一代产品Simpana 8
    查看>>